package com.ciwong.epaper.modules.me.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.application.EApplication;
import com.ciwong.epaper.application.EpaperConstant;
import com.ciwong.epaper.modules.epaper.bean.EpaperInfo;
import com.ciwong.epaper.modules.epaper.util.EpaperJumpManager;
import com.ciwong.epaper.modules.me.bean.BookDeskBean;
import com.ciwong.epaper.modules.me.bean.BookmarkBean;
import com.ciwong.epaper.modules.me.bean.FunctionsBean;
import com.ciwong.epaper.modules.me.bean.SubjectBean;
import com.ciwong.epaper.modules.me.util.MeJumpManager;
import com.ciwong.epaper.modules.me.widget.SpaceItemDecoration;
import com.ciwong.epaper.modules.msg.bean.WorkContent;
import com.ciwong.epaper.modules.msg.bean.Ad;
import com.ciwong.epaper.modules.pigai.util.PigaiJumpManager;
import com.ciwong.epaper.modules.reciteWords.util.WordJumpManager;
import com.ciwong.epaper.modules.viedoexplantion.util.ViedoJumpManager;
import com.ciwong.epaper.modules.wordlist.util.WorkBookJumpManager;
import com.ciwong.epaper.util.DoubleClickCheckUtils;
import com.ciwong.epaper.util.IntentValue;
import com.ciwong.epaper.util.RequestCode;
import com.ciwong.epaper.widget.FindItemView;
import com.ciwong.epaper.widget.JiaoCaiTongBuItemView;
import com.ciwong.epaper.widget.MyTopParousel;
import com.ciwong.epaper.widget.MyTopParouselViewPager;
import com.ciwong.epaper.widget.NoDataItemView;
import com.ciwong.epaper.widget.OnTopParouselListener;
import com.ciwong.epaper.widget.SearchItemView;
import com.ciwong.mobilelib.i.ViewOnClickListener;
import com.ciwong.mobilelib.widget.BuyServiceDialog;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by keepon on 2018/8/22.
 */
public class BookDeskRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private static final String TAG = "BookDeskRecyclerViewAda";
    /**
     * 搜索类型
     */
    public static final int ITEM_TYPE_SEARCH = 0;
    /**
     * 单词
     */
    public static final int ITEM_TYPE_MULTI_FUNCTION = 1;
    /**
     * 教材同步
     */
    public static final int ITEM_TYPE_JIAOCAITONGBU = 2;
    /**
     * 课外拓展
     */
    public static final int ITEM_TYPE_KEWAITUOZHAN = 3;
    /**
     * 趣味配音
     */
    public static final int ITEM_TYPE_DUBVIDEO = 4;

    /**
     * 发现
     */
    public static final int ITEM_TYPE_FIND = 5;

    /**
     * 没有可用的书籍
     */
    public static final int ITEM_TYPE_NODATA = 6;

    public ArrayList<Integer> itemShow = new ArrayList<>();
    /**
     * 背单词、单词pk、刷单词
     */
    private ArrayList<FunctionsBean> functionList = new ArrayList<>();
    /**
     * 教材同步
     */
    List<SubjectBean> mSubjectBeanList = new ArrayList<>();
    /**
     * 课外拓展
     */
    List<BookmarkBean> mBookmarkBeanList = new ArrayList<>();
    /**
     * 趣味配音
     */
    List<WorkContent> mDubvideoList = new ArrayList<>();
    /**
     * 广告轮播
     */
    List<Ad> mAdList = new ArrayList<>();
    List<String> imageList = new ArrayList<>();

    private MyTopParousel topParousel;

    BookDeskBean mBookDeskBean;
    private boolean mIsLocal;
    private Activity mContext;

    public BookDeskRecyclerViewAdapter(Activity context, BookDeskBean bokDeskBean) {
        mContext = context;
        mBookDeskBean = bokDeskBean;
        initFunctionsData();
    }

    private void initFunctionsData() {
        FunctionsBean functionsReciteWord = new FunctionsBean();
        functionsReciteWord.setIconRec(R.mipmap.ic_recite_word);
        functionsReciteWord.setItemName(mContext.getResources().getString(R.string.bookdesk_recite_word));
        functionList.add(functionsReciteWord);

        FunctionsBean functionsPK = new FunctionsBean();
        functionsPK.setIconRec(R.mipmap.ic_word_pk);
        functionsPK.setItemName(mContext.getResources().getString(R.string.bookdesk_word_pk));
        functionList.add(functionsPK);

        FunctionsBean functionsFollow = new FunctionsBean();
        functionsFollow.setIconRec(R.mipmap.ic_word_follow);
        functionsFollow.setItemName(mContext.getResources().getString(R.string.bookdesk_word_follow));
        functionList.add(functionsFollow);

        FunctionsBean functionsError = new FunctionsBean();
        functionsError.setIconRec(R.mipmap.ic_error_word_new);
        functionsError.setItemName(mContext.getResources().getString(R.string.bookdesk_word_error));
        functionList.add(functionsError);

        FunctionsBean functionsSee = new FunctionsBean();
        functionsSee.setIconRec(R.mipmap.ico_see_see);
        functionsSee.setItemName(mContext.getResources().getString(R.string.bookdesk_word_see));
        functionList.add(functionsSee);

        FunctionsBean functionsphonetic_symbol = new FunctionsBean();
        functionsphonetic_symbol.setIconRec(R.mipmap.ico_symbol);
        functionsphonetic_symbol.setItemName(mContext.getResources().getString(R.string.bookdesk_phonetic_symbol));
        functionList.add(functionsphonetic_symbol);

//        FunctionsBean functionsdubbing = new FunctionsBean();
//        functionsdubbing.setIconRec(R.mipmap.ic_word_follow);
//        functionsdubbing.setItemName(mContext.getResources().getString(R.string.bookdesk_dubbing));
//        functionList.add(functionsdubbing);

        FunctionsBean functionsdubbing = new FunctionsBean();
        functionsdubbing.setIconRec(R.mipmap.ic_ai_kouyu);
        functionsdubbing.setItemName(mContext.getResources().getString(R.string.bookdesk_ai_kouyu));
        functionList.add(functionsdubbing);


//        FunctionsBean functionsdictation = new FunctionsBean();
//        functionsdictation.setIconRec(R.mipmap.ic_error_word);
//        functionsdictation.setItemName(mContext.getResources().getString(R.string.bookdesk_dictation));
//        functionList.add(functionsdictation);

        FunctionsBean functionsdictation = new FunctionsBean();
        functionsdictation.setIconRec(R.mipmap.ic_error_word);
        functionsdictation.setItemName(mContext.getResources().getString(R.string.bookdesk_new_read));
        functionList.add(functionsdictation);

        FunctionsBean functionsessay = new FunctionsBean();
        functionsessay.setIconRec(R.mipmap.ic_recite_word);
        functionsessay.setItemName(mContext.getResources().getString(R.string.bookdesk_essay));
        functionList.add(functionsessay);
    }

    /**
     * 初始化头部轮播
     */
    private View initHead() {
        if (topParousel == null) {
            topParousel = new MyTopParousel(mContext, imageList);
            topParousel.setClick(new OnTopParouselListener() {
                @Override
                public void avertRepeatOnClick(int position) {
                    if (position < 0 || position >= mAdList.size()) {
                        return;
                    }
                    Ad mAd = mAdList.get(position);
                    if (mAd != null) {
                        if (mAd.getLinkType() == 2) {
                            if (mAd.getLinkAddress() != null && !TextUtils.isEmpty(mAd.getLinkAddress().trim())) {
                                MeJumpManager.jumpToCommonH5Activity(mContext, R.string.go_back, "", mAd.getLinkAddress().trim());
                            }
                        } else if (mAd.getLinkType() == 1) {
                            if (mAd.getSalesType() == 0) {
                                //跳服务
                                jumpToBookOrServerDetails(mAd.getServiceId());
                            } else {
                                EpaperInfo mEpaperInfo = new EpaperInfo();
                                mEpaperInfo.setPackageId(mAd.getServiceId() + "");
                                mEpaperInfo.setPeriodName(mAd.getServiceName());
                                //跳书籍
                                EpaperJumpManager.jumpToCatalog(R.string.go_back, mContext, mEpaperInfo,
                                        IntentValue.JumpToBookCatalogType.FROM_DESK_BOOK, -1, mAd.getServiceId());
                            }
                        }
                    }
                }

                @Override
                public void onShuffling(int position) {
                    // 上报广告
                }
            });
        } else {
            topParousel.setImageUrlList(imageList);
        }
        return topParousel.initView(true);
    }

    /**
     * 调到服务详情（购买页）
     */
    private void jumpToBookOrServerDetails(int serviceId) {
        String checkValidMsg = null;
        MeJumpManager.jumpBuyService(mContext, R.string.go_back, serviceId, -1, RequestCode.MainActivityResquestCode.REQUEST_CODE_TO_PAY, checkValidMsg);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == ITEM_TYPE_SEARCH) {
            return new SearchViewHolder(new SearchItemView(mContext));
        } else if (viewType == ITEM_TYPE_FIND) {
//            return new SearchViewHolder(new FindItemView(mContext));
            return new SearchViewHolder(initHead());
        } else if (viewType == ITEM_TYPE_MULTI_FUNCTION) {
            View functionsView = LayoutInflater.from(mContext).inflate(R.layout.layout_functions_item, parent, false);
            return new FunctionsViewHolder(functionsView);
        } else if (viewType == ITEM_TYPE_KEWAITUOZHAN) {
            View kewaiItemView = LayoutInflater.from(mContext).inflate(R.layout.layout_jiaocaitongbu_item, parent, false);
            return new BookMarkViewHolder(kewaiItemView);
        } else if (viewType == ITEM_TYPE_DUBVIDEO) {
            View dubVideoItemView = LayoutInflater.from(mContext).inflate(R.layout.layout_jiaocaitongbu_item, parent, false);
            return new DubVideoViewHolder(dubVideoItemView);
        } else if (viewType == ITEM_TYPE_JIAOCAITONGBU) {
            return new SubjectViewHolder(new JiaoCaiTongBuItemView(mContext));
        } else {
            return new SearchViewHolder(new NoDataItemView(mContext));
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        int itemViewType = getItemViewType(position);
        if (itemViewType == ITEM_TYPE_SEARCH) {
        } else if (itemViewType == ITEM_TYPE_MULTI_FUNCTION) {
            FunctionsViewHolder functionsViewHolder = (FunctionsViewHolder) holder;
            functionsViewHolder.bindFunctionsData(functionList);
        } else if (itemViewType == ITEM_TYPE_FIND) {
            topParousel.processData(true);
        } else if (itemViewType == ITEM_TYPE_JIAOCAITONGBU) {
            SubjectViewHolder subjectViewHolder = (SubjectViewHolder) holder;
            subjectViewHolder.bindSubjectData(mSubjectBeanList, mIsLocal);
        } else if (itemViewType == ITEM_TYPE_DUBVIDEO) {
            DubVideoViewHolder dubVideoViewHolder = (DubVideoViewHolder) holder;
            dubVideoViewHolder.bindDubVideoData(mDubvideoList, mIsLocal);
        } else if (itemViewType == ITEM_TYPE_KEWAITUOZHAN) {
            BookMarkViewHolder bookMarkViewHolder = (BookMarkViewHolder) holder;
            bookMarkViewHolder.bindBookMarkData(mBookmarkBeanList, mIsLocal);
        } else {
            //默认没有数据
        }
    }

    @Override
    public int getItemViewType(int position) {
        if (position >= 0 && position < itemShow.size()) {
            return itemShow.get(position);
        } else {
            //搜索
            return ITEM_TYPE_SEARCH;
        }

    }

    public int getCount(List<SubjectBean> subjectBeanList, List<BookmarkBean> bookmarkBeanList, List<WorkContent> dubvideo,
                        List<Ad> ads, ArrayList<FunctionsBean> functionList) {
        itemShow.clear();
        //添加搜索
        itemShow.add(ITEM_TYPE_SEARCH);
        boolean isNodata = true;
        //广告没数据隐藏起来
        if (ads != null && ads.size() > 0) {
            itemShow.add(ITEM_TYPE_FIND);
        }
        //背单词没数据隐藏起来
        if (functionList != null && functionList.size() > 0) {
            itemShow.add(ITEM_TYPE_MULTI_FUNCTION);
        }
        //教材同步没数据隐藏起来
        if (subjectBeanList != null && subjectBeanList.size() > 0) {
            itemShow.add(ITEM_TYPE_JIAOCAITONGBU);
            isNodata = false;
        }
        //趣味配音没数据隐藏起来
        if (dubvideo != null && dubvideo.size() > 0) {
            itemShow.add(ITEM_TYPE_DUBVIDEO);
        }
        //课外拓展没数据隐藏起来
        if (bookmarkBeanList != null && bookmarkBeanList.size() > 0) {
            itemShow.add(ITEM_TYPE_KEWAITUOZHAN);
            isNodata = false;
        }
        if (isNodata) {
            itemShow.add(ITEM_TYPE_NODATA);
        }
        return itemShow.size();
    }

    @Override
    public int getItemCount() {
        return getCount(mSubjectBeanList, mBookmarkBeanList, mDubvideoList, mAdList, functionList);
    }

    public void updateData(BookDeskBean bookDeskBean, boolean isLocal) {
        mBookDeskBean = bookDeskBean;
        mIsLocal = isLocal;
        mSubjectBeanList.clear();
        mSubjectBeanList.addAll(bookDeskBean.getSubject());
        mBookmarkBeanList.clear();
        mBookmarkBeanList.addAll(bookDeskBean.getBookmark());
        mDubvideoList.clear();
        mDubvideoList.addAll(bookDeskBean.getDubvideo());
        imageList.clear();
        mAdList.clear();
        if (bookDeskBean.getAds() != null) {
            mAdList.addAll(bookDeskBean.getAds());
        }
        for (int i = 0; i < mAdList.size(); i++) {
            imageList.add(mAdList.get(i).getPhoto());
        }
        notifyDataSetChanged();
    }

    /**
     * 搜索适配器
     */
    public class SearchViewHolder extends RecyclerView.ViewHolder {

        public SearchViewHolder(View itemView) {
            super(itemView);
        }
    }

    /**
     * 单词适配器
     */
    public class FunctionsViewHolder extends RecyclerView.ViewHolder {

        private RecyclerView rvFunction;
        private ArrayList<FunctionsBean> functionList;
        private NewBookFunctionsAdapter functionBookAdapter;

        public FunctionsViewHolder(View itemView) {
            super(itemView);
            initView(itemView);
        }

        private void initView(View itemView) {
            functionList = new ArrayList<>();
            rvFunction = itemView.findViewById(R.id.rv_functions);

            rvFunction.setLayoutManager(new GridLayoutManager(mContext, 3));
            functionBookAdapter = new NewBookFunctionsAdapter(mContext, functionList);
            rvFunction.setAdapter(functionBookAdapter);
            functionBookAdapter.setOnItemClickListener(new BaseNewBookItemInAdapter.OnItemClickListener<FunctionsBean>() {
                @Override
                public void onItemClick(int positon, FunctionsBean bookmarkBean) {
                    if (DoubleClickCheckUtils.vertifyDuration()) {
                        if (mContext.getResources().getString(R.string.bookdesk_recite_word).equals(bookmarkBean.getItemName())) {
                            //跳转背单词
                            WordJumpManager.gotoWordPlan(mContext);
                        } else if (mContext.getResources().getString(R.string.bookdesk_word_pk).equals(bookmarkBean.getItemName())) {
                            //跳转单词PK
                            WordJumpManager.jumpToWordPKActivity(R.string.go_back, mContext);
                        } else if (mContext.getResources().getString(R.string.bookdesk_word_follow).equals(bookmarkBean.getItemName())) {
                            //跳转刷单词
                            WorkBookJumpManager.jumpToWorkBookActivity(R.string.go_back, mContext);
                        } else if (mContext.getResources().getString(R.string.bookdesk_word_error).equals(bookmarkBean.getItemName())) {
                            //跳转错题本
                            WorkBookJumpManager.jumpToErrorWorkActivity(R.string.go_back, mContext);
                        } else if (mContext.getResources().getString(R.string.bookdesk_word_see).equals(bookmarkBean.getItemName())) {
                            //跳转看一看
                            MeJumpManager.jumpToFindH5Activity(mContext, R.string.go_back, mContext.getString(R.string.bookdesk_word_see));
                        } else if (mContext.getResources().getString(R.string.bookdesk_phonetic_symbol).equals(bookmarkBean.getItemName())) {
                            //跳转音标专练
                            ViedoJumpManager.jumpToPhoneticSymbol(R.string.go_back, mContext);
                        } else if (mContext.getResources().getString(R.string.bookdesk_ai_kouyu).equals(bookmarkBean.getItemName())) {
                             //跳转AI口语
                            ViedoJumpManager.jumpToAiSpokenActivity(R.string.go_back, mContext);
                        }
                        else if (mContext.getResources().getString(R.string.bookdesk_dubbing).equals(bookmarkBean.getItemName())) {
                            EApplication application = (EApplication) mContext.getApplication();
                            if (application != null && application.isServiceExpired()) {
                                //跳转趣配音
                                MeJumpManager.jumpToDubVideoListActivity(R.string.go_back, (Activity) mContext);
                            } else {
                                setBuyServiceDialog();
                            }
                        } else if (mContext.getResources().getString(R.string.bookdesk_dictation).equals(bookmarkBean.getItemName())) {
                            //跳转报听写
                            MeJumpManager.jumpToBookTagDictationActivity(R.string.go_back, 0, mContext.getResources().getString(R.string.bookdesk_dictation), (Activity) mContext);
                        } else if (mContext.getResources().getString(R.string.bookdesk_new_read).equals(bookmarkBean.getItemName())) {
                            //跳转报听写
                            MeJumpManager.jumpTNewBookReadActivity(R.string.go_back, 2, mContext.getResources().getString(R.string.bookdesk_new_read), (Activity) mContext);
                        } else if (mContext.getResources().getString(R.string.bookdesk_essay).equals(bookmarkBean.getItemName())) {
                            EApplication application = (EApplication) mContext.getApplication();
                            if (application != null && application.isServiceExpired()) {
                                //跳转作文
                                PigaiJumpManager.jumpToPigaiStartActivity(mContext, R.string.go_back);
                            } else {
                                setBuyServiceDialog();
                            }
                        }
                    }
                }
            });
        }

        private BuyServiceDialog buyServiceDialog;

        public void setBuyServiceDialog() {
            if (buyServiceDialog == null) {
                buyServiceDialog = new BuyServiceDialog(mContext);
                buyServiceDialog.setMenuOnClickListeners(new ViewOnClickListener() {
                    @Override
                    public void avertRepeatOnClick(View v) {
                        //拓展服务
                        MeJumpManager.jumpToResourseCenterH5Activity(mContext, R.string.go_back, mContext.getResources().getString(R.string.resource_center));
                        buyServiceDialog.dismiss();
                    }
                });
                buyServiceDialog.setClosOnClickListeners(new ViewOnClickListener() {
                    @Override
                    public void avertRepeatOnClick(View v) {
                        buyServiceDialog.dismiss();
                    }
                });
            }
            buyServiceDialog.show();
        }

        private void bindFunctionsData(ArrayList<FunctionsBean> functionList) {
            functionBookAdapter.updateList(functionList);
        }
    }

    /**
     * 同步教材适配器
     */
    public class SubjectViewHolder extends RecyclerView.ViewHolder {

        public SubjectViewHolder(View itemView) {
            super(itemView);
        }


        public void bindSubjectData(List<SubjectBean> subjectBeanList, boolean isLocal) {
            if (itemView instanceof JiaoCaiTongBuItemView) {
                JiaoCaiTongBuItemView jiaoCaiTongBuItemView = (JiaoCaiTongBuItemView) itemView;
                jiaoCaiTongBuItemView.bindData(mBookDeskBean, subjectBeanList, isLocal);
            }

        }
    }

    /**
     * 趣味配音适配器
     */
    public class DubVideoViewHolder extends RecyclerView.ViewHolder {
        List<WorkContent> mDubvideoList;
        TextView mTvTypeName;
        LinearLayout mLlMore;
        RecyclerView mExpansionRecyclerView;
        NewDubVideoExpansionAdapter mNewBookDeskExpansionAdapter;

        public DubVideoViewHolder(View itemView) {
            super(itemView);
            mTvTypeName = itemView.findViewById(R.id.tv_type_name);
            mLlMore = itemView.findViewById(R.id.ll_more_menu);
            mLlMore.setVisibility(View.VISIBLE);
            mExpansionRecyclerView = itemView.findViewById(R.id.recycler_view);
            mExpansionRecyclerView.setFocusable(false);
            mTvTypeName.setText("趣配音");
            mLlMore.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //点击更多跳转
                    EApplication application = (EApplication) mContext.getApplication();
                    if (application != null && application.isServiceExpired()) {
                        //跳转趣配音
                        MeJumpManager.jumpToDubVideoListActivity(R.string.go_back, (Activity) mContext);
                    } else {
                        setBuyServiceDialog();
                    }
                }
            });
            mExpansionRecyclerView.addItemDecoration(new SpaceItemDecoration(mContext, 10, 0, 0));
            mExpansionRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 2) {
                @Override
                public boolean canScrollHorizontally() {
                    return false;
                }

                @Override
                public boolean canScrollVertically() {
                    return false;
                }
            });
            mDubvideoList = new ArrayList<>();
            mNewBookDeskExpansionAdapter = new NewDubVideoExpansionAdapter(mContext, mDubvideoList);
            mExpansionRecyclerView.setAdapter(mNewBookDeskExpansionAdapter);
            mNewBookDeskExpansionAdapter.setOnItemClickListener(new NewDubVideoExpansionAdapter.OnItemClickListener<WorkContent>() {
                @Override
                public void onItemClick(int positon, WorkContent workContent) {
                    if (DoubleClickCheckUtils.vertifyDuration()) {
                        MeJumpManager.jumpToDubVideoDetailActivity(EpaperConstant.REQUEST_CODE_GET_VIDEO_MASTER_STATE, R.string.go_back,
                                (Activity) mContext, "", workContent, "0", 0, false);
                    }

                }
            });
        }

        private BuyServiceDialog buyServiceDialog;

        public void setBuyServiceDialog() {
            if (buyServiceDialog == null) {
                buyServiceDialog = new BuyServiceDialog(mContext);
                buyServiceDialog.setMenuOnClickListeners(new ViewOnClickListener() {
                    @Override
                    public void avertRepeatOnClick(View v) {
                        //拓展服务
                        MeJumpManager.jumpToResourseCenterH5Activity(mContext, R.string.go_back, mContext.getResources().getString(R.string.resource_center));
                        buyServiceDialog.dismiss();
                    }
                });
                buyServiceDialog.setClosOnClickListeners(new ViewOnClickListener() {
                    @Override
                    public void avertRepeatOnClick(View v) {
                        buyServiceDialog.dismiss();
                    }
                });
            }
            buyServiceDialog.show();
        }

        public void bindDubVideoData(List<WorkContent> dubvideo, boolean isLocal) {
            if (dubvideo != null) {
                if (dubvideo.size() == 1) {
                    mExpansionRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 1) {
                        @Override
                        public boolean canScrollHorizontally() {
                            return false;
                        }

                        @Override
                        public boolean canScrollVertically() {
                            return false;
                        }
                    });
                } else {
                    mExpansionRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 2) {
                        @Override
                        public boolean canScrollHorizontally() {
                            return false;
                        }

                        @Override
                        public boolean canScrollVertically() {
                            return false;
                        }
                    });
                }
            }
            mDubvideoList = dubvideo;
            mNewBookDeskExpansionAdapter.updateList(mDubvideoList);

        }
    }

    /**
     * 课外拓展适配器
     */
    public class BookMarkViewHolder extends RecyclerView.ViewHolder {
        List<BookmarkBean> mBookmarkBeanList;
        TextView mTvTypeName;
        LinearLayout mLlMore;
        RecyclerView mExpansionRecyclerView;
        NewBookDeskExpansionAdapter mNewBookDeskExpansionAdapter;

        public BookMarkViewHolder(View itemView) {
            super(itemView);
            mTvTypeName = itemView.findViewById(R.id.tv_type_name);
            mExpansionRecyclerView = itemView.findViewById(R.id.recycler_view);
            mLlMore = itemView.findViewById(R.id.ll_more_menu);
            mLlMore.setVisibility(View.GONE);
            mExpansionRecyclerView.setFocusable(false);
            mTvTypeName.setText("课外拓展");
            mExpansionRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 3) {
                @Override
                public boolean canScrollHorizontally() {
                    return false;
                }

                @Override
                public boolean canScrollVertically() {
                    return false;
                }
            });
            mBookmarkBeanList = new ArrayList<>();
            mNewBookDeskExpansionAdapter = new NewBookDeskExpansionAdapter(mContext, mBookmarkBeanList);
            mExpansionRecyclerView.setAdapter(mNewBookDeskExpansionAdapter);
            mNewBookDeskExpansionAdapter.setOnItemClickListener(new NewBookDeskExpansionAdapter.OnItemClickListener<BookmarkBean>() {
                @Override
                public void onItemClick(int positon, BookmarkBean bookmarkBean) {
                    if (DoubleClickCheckUtils.vertifyDuration()) {
                        MeJumpManager.jumpToBookTagActivity(R.string.go_back, bookmarkBean.getBookmarkId(), bookmarkBean.getBookmarkName(), (Activity) mContext);
                    }

                }
            });
        }


        public void bindBookMarkData(List<BookmarkBean> bookmarkBeanList, boolean isLocal) {
            if (bookmarkBeanList != null) {
                if (bookmarkBeanList.size() == 1) {
                    mExpansionRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 1) {
                        @Override
                        public boolean canScrollHorizontally() {
                            return false;
                        }

                        @Override
                        public boolean canScrollVertically() {
                            return false;
                        }
                    });
                } else if (bookmarkBeanList.size() == 2) {
                    mExpansionRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 2) {
                        @Override
                        public boolean canScrollHorizontally() {
                            return false;
                        }

                        @Override
                        public boolean canScrollVertically() {
                            return false;
                        }
                    });
                } else {
                    mExpansionRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 3) {
                        @Override
                        public boolean canScrollHorizontally() {
                            return false;
                        }

                        @Override
                        public boolean canScrollVertically() {
                            return false;
                        }
                    });

                }
            }
            mBookmarkBeanList = bookmarkBeanList;
            mNewBookDeskExpansionAdapter.updateList(mBookmarkBeanList);

        }
    }

}
